<template>
  <div class="copyright-box">
    <div class="heard-title">
      <titles title="文创商品" />
    </div>
    <div class="exbit-list">
      <div
        class="item-box"
        :class="{ 'item-box-no-mg': (index + 1) % 4 == 0 }"
        @click="pathLink(item.url)"
        v-for="(item, index) in list"
        :key="item.id"
      >
        <div
          class="item-shadow"
          :style="{
            background: colorList5[store.styleInfo.colorType - 1].shmentColor,
          }"
        ></div>
        <div class="item-info">
          <t-image
            class="item-info-image"
            :src="$filters.getLinkUrl(item.coverUrl + '?imageView2/1/h/240/format/webp')"
            fit="cover"
            position="center"
          >
            <template #error>
              <imageNull />
            </template>
          </t-image>
          <div class="item-info-shadow">
            <p
              class="item-title1"
              :style="{
                fontFamily: store.styleInfo.fontFamily,
              }"
            >
              {{ item.name }}
            </p>
            <span class="item-title2 item-title1"
              ><span
                :style="{
                  'font-size': '14px',
                }"
                v-if="item.price"
                >￥</span
              ><span v-if="item.price">{{ item.price }}</span
              ><span v-else class="noPrice">暂无价格</span></span
            >
          </div>
        </div>
      </div>
    </div>
    <t-row :gutter="20" style="margin-top: 50px">
      <t-col :xs="4" :sm="4" :md="4" :lg="4" :xl="4" :xxl="3" v-for="item in list" :key="item.id">
        <!-- <div class="item-box" @click="pathLink(item.url)">
          <img
            class="item-img t-image--fit-cover t-image--position-center"
            v-if="!item.coverUrl"
            src="http://101.34.143.36:8890/api/image/387939155165253"
            alt=""
          />
          <img
            class="item-img"
            v-else
            :src="$filters.getLinkUrl(item.coverUrl + '?imageView2/1/h/240/format/webp')"
            alt=""
          />
          <div class="item-content">
            <p
              class="item-title1"
              :style="{
                fontFamily: store.styleInfo.fontFamily,
              }"
            >
              {{ item.name }}
            </p>
            <div class="item-btm">
              <span
                :style="{
                  fontFamily: store.styleInfo.fontFamily,
                }"
                class="item-title2"
                >￥{{ item.price }}</span 
              >
              <span class="item-title3">参考价</span>
            </div> 
          </div>
        </div> -->
      </t-col>
    </t-row>
    <t-row style="margin-top: 10px" v-if="total > parmas.pageSize">
      <t-col class="pagination-content" :span="12" :class="'pagination-content-style' + store.styleInfo.colorType">
        <paginationPage @change="change" :current="parmas.pageNo" :pageSize="parmas.pageSize" :total="total" />
      </t-col>
    </t-row>
    <div v-if="total == 0">暂无相关数据</div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import imageNull from '@/components/imageNull/index.vue';
import paginationPage from '../components/paginationPage.vue';
import { pagerCount } from '@/utils/minxin';
import { colorList5 } from '../../data';
import titles from '../components/title.vue';
import { urls } from '@/utils/request/upload';
import { goodsList } from '@/api/goods/goods';
import { ref, reactive, onActivated } from 'vue';
import { MessagePlugin } from 'tdesign-vue-next';
import { useProjectStore } from '@/store';

const store = useProjectStore();
const current = ref(1);
const pageSize = ref(20);
const parmas = reactive({
  value: '',
  pageNo: 1,
  pageSize: 8,
});

const width = window.innerWidth;
if (width >= 1880) {
  parmas.pageSize = 16;
} else {
  parmas.pageSize = 12;
}
const pageMax = ref(1);
const list = ref([]);
const total = ref(0);
const loading = ref(false);

const init = async () => {
  try {
    if (loading.value) {
      return;
    }
    loading.value = true;
    let res = await goodsList(localStorage.getItem('projectId'), parmas);
    total.value = res.data.total;
    list.value = res.data.data;
    pageMax.value = pagerCount(total.value, parmas.pageSize);

    loading.value = false;
  } catch {
    loading.value = false;
  }
};
onActivated(() => {
  init();
});

const addParmasNo = (e: number) => {
  parmas.pageNo = e;
  init();
};
const onPageSizeChange = (size) => {
  init();
  // console.log('page-size:', size);
  // MessagePlugin.success(`pageSize变化为${size}`);
};

const change = (e: any) => {
  // console.log(e);
  parmas.pageNo = e.page;
  init();
};
const onCurrentChange = (index, pageInfo) => {
  init();
  // MessagePlugin.success(`转到第${index}页`);
  // console.log(pageInfo);
};

const pathLink = (url: string) => {
  console.log(url);
  if (!url) {
    return;
  }
  window.open(url, '_blank');
};
</script>

<style lang="less" scoped>
@import '../index.less';
.copyright-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 1180px;
  min-width: 1180px;
  padding-bottom: 80px;
}
.item-title1 {
  text-align: center;
  width: 100%;
  font-size: 18px;
  color: #333333;
  line-height: 28px;
  color: #ffffff;
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden; //溢出内容隐藏
  text-overflow: ellipsis; //文本溢出部分用省略号表示
  display: -webkit-box; //特别显示模式
  -webkit-line-clamp: 1; //行数
  line-clamp: 1;
  -webkit-box-orient: vertical; //盒子中内容竖直排列
  line-height: 28px;
  height: 28px;
}
.item-title2 {
  font-size: 22px;
  font-family: DIN-Medium, DIN;
  color: #ffffff;
  line-height: 34px;
}
.exbit-list {
  display: flex;
  flex-wrap: wrap;

  width: 100%;
}
.item-info {
  cursor: pointer;
  position: relative;
  width: 220px;
  height: 220px;
  z-index: 10;
}
.item-info-image {
  width: 220px;
  height: 220px;
}
.item-box {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 257px;
  height: 257px;
  margin-right: 50px;
  margin-bottom: 50px;
}
.item-box-no-mg {
  margin-right: 0px;
}
.item-info-shadow {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 11;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 16px;
  background: rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: all 0.4s;
}
.item-shadow {
  position: absolute;
  top: 24.5px;
  left: 24.5px;
  width: 220px;
  height: 220px;
  transform: rotate(75deg);
}
.item-info:hover {
  .item-info-shadow {
    opacity: 1;
  }
}
.t-row {
  width: 100%;
}
.t-col {
  margin-bottom: 0;
}
.heard-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-bottom: 85px;
}
.noPrice {
  font-size: 14px;
  line-height: normal;
  opacity: 0.38;
}
</style>
